package com.atguigu.dao.impl;

import com.atguigu.dao.BaseDao;
import com.atguigu.dao.UserDao;
import com.atguigu.domain.User;

/**
 * user dao impl
 * @author dl
 * @create 2020-04-18-11:27
 */
public class UserDaoImpl extends BaseDao<User> implements UserDao  {
	/**
	 * get user by name and password
	 * @param user
	 * @return User
	 */
	@Override
	public User getUserByNameAndPassword(User user) {
		String sql = "select * from bs_user where username = ? and password = ?";
		User bean = getBean(sql, user.getUsername(), user.getPassword());
		return bean;
	}

	/**
	 * user register
	 * @param user
	 * @return boolean true:success false:failed
	 */
	@Override
	public boolean registerUser(User user) {
		String sql = "insert into bs_user(username,password,email) values(?,?,?)";
		int update = update(sql, user.getUsername(), user.getPassword(), user.getEmail());
		return update > 0;
	}

	/**
	 * username is exists
	 * @param username
	 * @return
	 */
	@Override
	public User existsName(String username) {
		String sql = "select * from bs_user where username = ?";
		return getBean(sql,username);
	}
}
